<?php

namespace App\Http\Controllers\WeChat;


use App\Http\Controllers\Account\Controller;
use App\Http\Requests\WeChatRequest;
use App\Models\Site;

use App\Models\WeChat;
use Illuminate\Http\Request;

class WeChatController extends Controller
{
    public function index(Site $site)
    {
        $wechats = WeChat::all();
        return view('wechat.wechat.index', compact('site', 'wechats'));
    }

    public function create(Site $site, WeChat $wechat)
    {

        return view('wechat.wechat.create', compact('site', 'wechat'));
    }

    public function store(WeChatRequest $request, Site $site, WeChat $wechat)
    {
        $wechat->site_id = $site->id;
        $wechat->fill($request->all())->save();
//
        return redirect()->route('wechat.wechat.index', $site)->with('success', '公众号添加成功');


    }

//参数根据路由要区分大小写
    public function edit(Site $site, WeChat $wechat)
    {
        return view('wechat.wechat.edit', compact('site', 'wechat'));
    }

    public function update(WeChatRequest $request, Site $site, WeChat $wechat)
    {

        $wechat->fill($request->all())->save();
        return redirect()->route('wechat.wechat.index', $site)->with('success', '公众号保存成功');
    }

    public function destroy(Site $site, WeChat $wechat)
    {
        $wechat->delete();
        return response()->json(['message' => '公众号已经删除']);
    }
}
